package com.we823.cms.controller.manage.cms;

import javax.servlet.http.HttpServletRequest;

import com.github.pagehelper.PageInfo;
import com.we823.cms.common.web.pageable.PageRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.we823.cms.common.WebConstants;
import com.we823.cms.controller.manage.AbstractManageController;
import com.we823.cms.model.cms.Template;
import com.we823.cms.repository.service.cms.TemplateService;

@Controller
@RequestMapping(WebConstants.MANAGE_URL + "/template")
public class TemplateManageController extends AbstractManageController<Template, Integer> {

	private String baseUrl = WebConstants.WEB_MANAGE_TEMPLATE_BaseUrl + "template/";

	private TemplateService templateService;

	@Autowired
	public TemplateManageController(TemplateService templateService) {
		super(templateService);
		super.baseUrl = baseUrl;
		this.templateService = templateService;
	}

	@Override
	public PageInfo<Template> getData(PageRequest pageRequest, HttpServletRequest request, Model model, boolean pageable) {
		PageInfo<Template> templatePage = null;
		if(pageable){
			templatePage = templateService.findAll(pageRequest);
		}else{
			templatePage = new PageInfo<>(templateService.findAll());
		}
		return templatePage;
	}

	@Override
	public void setIndetity() {
		setResourceIdentity("cms:template");
	}

}
